from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-08 14:05:29.951460
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 08, May, 2021
Time: 14:05:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0869
Nobs: 285.000 HQIC: -48.7779
Log likelihood: 3467.16 FPE: 4.12415e-22
AIC: -49.2403 Det(Omega_mle): 3.02371e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393192 0.115996 3.390 0.001
L1.Burgenland 0.072245 0.059060 1.223 0.221
L1.Kärnten -0.224588 0.052550 -4.274 0.000
L1.Niederösterreich 0.108373 0.126599 0.856 0.392
L1.Oberösterreich 0.217766 0.122644 1.776 0.076
L1.Salzburg 0.277096 0.067347 4.114 0.000
L1.Steiermark 0.108565 0.086134 1.260 0.208
L1.Tirol 0.121084 0.059605 2.031 0.042
L1.Vorarlberg -0.031282 0.054787 -0.571 0.568
L1.Wien -0.034481 0.109905 -0.314 0.754
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.421046 0.133763 3.148 0.002
L1.Burgenland 0.004118 0.068107 0.060 0.952
L1.Kärnten 0.329003 0.060599 5.429 0.000
L1.Niederösterreich 0.122701 0.145991 0.840 0.401
L1.Oberösterreich -0.070607 0.141430 -0.499 0.618
L1.Salzburg 0.228807 0.077662 2.946 0.003
L1.Steiermark 0.089099 0.099328 0.897 0.370
L1.Tirol 0.136674 0.068736 1.988 0.047
L1.Vorarlberg 0.152413 0.063179 2.412 0.016
L1.Wien -0.404443 0.126739 -3.191 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.251654 0.058861 4.275 0.000
L1.Burgenland 0.105079 0.029970 3.506 0.000
L1.Kärnten -0.013894 0.026666 -0.521 0.602
L1.Niederösterreich 0.094724 0.064241 1.475 0.140
L1.Oberösterreich 0.281350 0.062234 4.521 0.000
L1.Salzburg 0.021914 0.034174 0.641 0.521
L1.Steiermark -0.002224 0.043708 -0.051 0.959
L1.Tirol 0.067692 0.030246 2.238 0.025
L1.Vorarlberg 0.076328 0.027801 2.746 0.006
L1.Wien 0.119089 0.055770 2.135 0.033
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206088 0.056243 3.664 0.000
L1.Burgenland 0.028493 0.028637 0.995 0.320
L1.Kärnten 0.009409 0.025480 0.369 0.712
L1.Niederösterreich 0.056895 0.061384 0.927 0.354
L1.Oberösterreich 0.393289 0.059467 6.614 0.000
L1.Salzburg 0.081808 0.032655 2.505 0.012
L1.Steiermark 0.131551 0.041764 3.150 0.002
L1.Tirol 0.051467 0.028901 1.781 0.075
L1.Vorarlberg 0.081647 0.026565 3.073 0.002
L1.Wien -0.041465 0.053290 -0.778 0.437
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.435280 0.110717 3.931 0.000
L1.Burgenland 0.104328 0.056373 1.851 0.064
L1.Kärnten 0.010470 0.050159 0.209 0.835
L1.Niederösterreich 0.032594 0.120838 0.270 0.787
L1.Oberösterreich 0.116945 0.117063 0.999 0.318
L1.Salzburg 0.060134 0.064282 0.935 0.350
L1.Steiermark 0.064481 0.082215 0.784 0.433
L1.Tirol 0.199081 0.056893 3.499 0.000
L1.Vorarlberg 0.038628 0.052294 0.739 0.460
L1.Wien -0.057071 0.104904 -0.544 0.586
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217310 0.086765 2.505 0.012
L1.Burgenland -0.012079 0.044177 -0.273 0.785
L1.Kärnten -0.006189 0.039308 -0.157 0.875
L1.Niederösterreich -0.015237 0.094697 -0.161 0.872
L1.Oberösterreich 0.415896 0.091738 4.534 0.000
L1.Salzburg 0.011933 0.050376 0.237 0.813
L1.Steiermark -0.027971 0.064429 -0.434 0.664
L1.Tirol 0.162071 0.044585 3.635 0.000
L1.Vorarlberg 0.058033 0.040981 1.416 0.157
L1.Wien 0.202177 0.082209 2.459 0.014
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192707 0.106216 1.814 0.070
L1.Burgenland 0.024111 0.054081 0.446 0.656
L1.Kärnten -0.069895 0.048120 -1.453 0.146
L1.Niederösterreich -0.041712 0.115926 -0.360 0.719
L1.Oberösterreich 0.012777 0.112304 0.114 0.909
L1.Salzburg 0.086241 0.061669 1.398 0.162
L1.Steiermark 0.318542 0.078872 4.039 0.000
L1.Tirol 0.456248 0.054580 8.359 0.000
L1.Vorarlberg 0.148969 0.050168 2.969 0.003
L1.Wien -0.126001 0.100639 -1.252 0.211
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207940 0.125816 1.653 0.098
L1.Burgenland 0.039952 0.064061 0.624 0.533
L1.Kärnten -0.074499 0.056999 -1.307 0.191
L1.Niederösterreich 0.116788 0.137318 0.850 0.395
L1.Oberösterreich 0.012517 0.133028 0.094 0.925
L1.Salzburg 0.193795 0.073049 2.653 0.008
L1.Steiermark 0.130162 0.093427 1.393 0.164
L1.Tirol 0.055178 0.064652 0.853 0.393
L1.Vorarlberg 0.106631 0.059426 1.794 0.073
L1.Wien 0.219555 0.119210 1.842 0.066
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.499179 0.070125 7.118 0.000
L1.Burgenland -0.012825 0.035705 -0.359 0.719
L1.Kärnten -0.017272 0.031769 -0.544 0.587
L1.Niederösterreich 0.110592 0.076536 1.445 0.148
L1.Oberösterreich 0.302683 0.074144 4.082 0.000
L1.Salzburg 0.023605 0.040714 0.580 0.562
L1.Steiermark -0.046971 0.052072 -0.902 0.367
L1.Tirol 0.081609 0.036035 2.265 0.024
L1.Vorarlberg 0.103832 0.033122 3.135 0.002
L1.Wien -0.041898 0.066443 -0.631 0.528
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.161935 0.094162 0.169458 0.221854 0.077560 0.089728 0.000851 0.165305
Kärnten 0.161935 1.000000 0.056123 0.212566 0.186439 -0.067072 0.177694 0.021041 0.308113
Niederösterreich 0.094162 0.056123 1.000000 0.244154 0.098802 0.317501 0.151770 0.025289 0.320138
Oberösterreich 0.169458 0.212566 0.244154 1.000000 0.300681 0.260343 0.102680 0.061365 0.143591
Salzburg 0.221854 0.186439 0.098802 0.300681 1.000000 0.148961 0.076521 0.090519 0.030323
Steiermark 0.077560 -0.067072 0.317501 0.260343 0.148961 1.000000 0.093592 0.100690 -0.100254
Tirol 0.089728 0.177694 0.151770 0.102680 0.076521 0.093592 1.000000 0.151808 0.159792
Vorarlberg 0.000851 0.021041 0.025289 0.061365 0.090519 0.100690 0.151808 1.000000 -0.010025
Wien 0.165305 0.308113 0.320138 0.143591 0.030323 -0.100254 0.159792 -0.010025 1.000000